package com.viking.car;


import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

public class Constants {
    //public static final int PACKAGE_HEADER = -517221512;  //头字段固定值，0xE1 0x2B 0xD3 0x78
    public static final int PACKAGE_HEADER = 0xE12BD378;  //头字段固定值，0xE1 0x2B 0xD3 0x78
    public static short PACKAGE_FOOTER = -1;  //尾字段固定值,0xFF 0xFF
    public static final short VERSION = 1;        //版本
    public static final int HEADER_FOOTER_LENGTH = 26;//头和尾的总长度(字节数)
    public static final int TAKE_CAR =        0x00000001;
    public static final int OPEN_DOOR =       0x00000002;
    public static final int LOCK_DOOR =       0x00000003;
    public static final int RETURN_CAR =      0x00000004;
    public static final int QUERYPOWER =      0x00000005;
    public static final int TAKE_CAR_RESP =   0x80000001;
    public static final int OPEN_DOOR_RESP =  0x80000002;
    public static final int LOCK_DOOR_RESP =  0x80000003;
    public static final int RETURN_CAR_RESP = 0x80000004;
    public static final int QUERYPOWER_RESP = 0x80000005;
    //请求和响应的commandid的映射
    public static Map<Integer,Integer> COMMANDID_MAP = new HashMap<Integer, Integer>();
    //响应的commandId和对应的错误码映射
    public static Map<Integer,Map<Integer,String>> RESP_CODE_MAP = new HashMap<Integer, Map<Integer, String>>();
    public static final int MESSAGE_SRUCT_ERROR = 1;
    public static final int TOKEN_ERROR = 2;
    public static final int REPEAT_ERROR = 3;
    static {
        COMMANDID_MAP.put(TAKE_CAR,TAKE_CAR_RESP);
        COMMANDID_MAP.put(OPEN_DOOR,OPEN_DOOR_RESP);
        COMMANDID_MAP.put(LOCK_DOOR,LOCK_DOOR_RESP);
        COMMANDID_MAP.put(RETURN_CAR,RETURN_CAR_RESP);
        COMMANDID_MAP.put(QUERYPOWER,QUERYPOWER_RESP);
        //取车错误响应码
        Map<Integer,String> TAKE_CAR_RESP_CODE = new HashMap<Integer, String>();
        TAKE_CAR_RESP_CODE.put(MESSAGE_SRUCT_ERROR,"10101");
        TAKE_CAR_RESP_CODE.put(TOKEN_ERROR,"10102");
        TAKE_CAR_RESP_CODE.put(REPEAT_ERROR,"10103");
        //开门错误响应码
        Map<Integer,String> OPEN_DOOR_RESP_CODE = new HashMap<Integer, String>();
        OPEN_DOOR_RESP_CODE.put(MESSAGE_SRUCT_ERROR,"10136");
        OPEN_DOOR_RESP_CODE.put(TOKEN_ERROR,"10137");
        OPEN_DOOR_RESP_CODE.put(REPEAT_ERROR,"10138");
        //锁门错误响应码
        Map<Integer,String> LOCK_DOOR_RESP_CODE = new HashMap<Integer, String>();
        LOCK_DOOR_RESP_CODE.put(MESSAGE_SRUCT_ERROR,"10171");
        LOCK_DOOR_RESP_CODE.put(TOKEN_ERROR,"10172");
        LOCK_DOOR_RESP_CODE.put(REPEAT_ERROR,"10173");
        //还车错误响应码
        Map<Integer,String> RETURN_CAR_RESP_CODE = new HashMap<Integer, String>();
        RETURN_CAR_RESP_CODE.put(MESSAGE_SRUCT_ERROR,"10200");
        RETURN_CAR_RESP_CODE.put(TOKEN_ERROR,"10201");
        RETURN_CAR_RESP_CODE.put(REPEAT_ERROR,"10202");
        //查询剩余电量错误响应码
        Map<Integer,String> QUERYPOWER_RESP_CODE = new HashMap<Integer, String>();
        QUERYPOWER_RESP_CODE.put(MESSAGE_SRUCT_ERROR,"10231");
        QUERYPOWER_RESP_CODE.put(TOKEN_ERROR,"10233");

        RESP_CODE_MAP.put(TAKE_CAR_RESP,TAKE_CAR_RESP_CODE);
        RESP_CODE_MAP.put(OPEN_DOOR_RESP,OPEN_DOOR_RESP_CODE);
        RESP_CODE_MAP.put(LOCK_DOOR_RESP,LOCK_DOOR_RESP_CODE);
        RESP_CODE_MAP.put(RETURN_CAR_RESP,RETURN_CAR_RESP_CODE);
        RESP_CODE_MAP.put(QUERYPOWER_RESP,QUERYPOWER_RESP_CODE);
    }

    public static void main(String[] args) throws Exception {
        System.out.println(TAKE_CAR_RESP);
        System.out.println(OPEN_DOOR_RESP);
        System.out.println(LOCK_DOOR_RESP);
        System.out.println(RETURN_CAR_RESP);
        FileOutputStream fos =
                new FileOutputStream("C:\\Users\\Administrator\\Desktop\\a.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        dos.writeInt(0x80000001);
        dos.writeInt(0x80000002);
        dos.writeInt(0x80000003);
        dos.writeInt(0x80000004);
        dos.writeInt(0xe12bd378);
        dos.writeInt(0xffff);
        System.out.println(0xe12bd378);
        System.out.println((short)0xffff);
        dos.flush();
        dos.close();
        fos.close();

    }
}
